package myThread;

class MyRunnable implements Runnable{

    @Override
    public void run() {
        while(true){
            System.out.println("hello Thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class demo2 {
    public static void main(String[] args) throws InterruptedException {
        Runnable myRunnable = new MyRunnable();//父类接口的引用变量指向子类实例
        Thread t = new Thread(myRunnable);
        t.start();//还是需要用到 t (Thread) 来开启线程
        while (true){
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}

